class ApplicationController < ActionController::Base
  protect_from_forgery

  def authenticate!
    if current_user.nil?
      redirect_to root_url, :alert => "You must first log in to access this page"
    end
  end

  def protect_from_student
    if current_user.student?
      redirect_to actions_url, :alert => "Not authorized for this action"
    end
  end

  def protect_from_instructor
    if current_user.instructor?
      redirect_to actions_url, :alert => "Not authorized for this action"
    end
  end

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
  helper_method :current_user
end
